export class DomUtils {
  static convertToDom(strHtml) {
    const parser = new DOMParser();
    const doc = parser.parseFromString(strHtml, "text/html");
    return doc.body.firstChild;
  }
  static insertElement(element, target) {
    const container =
      typeof target === "string" ? document.querySelector(target) : target;
    if (container) {
      container.appendChild(element);
    } else {
      console.error("目标容器未找到");
    }
  }

  static replaceElement(newElement, target) {
    const oldElement =
      typeof target === "string" ? document.querySelector(target) : target;
    if (oldElement) {
      oldElement.replaceWith(newElement);
    } else {
      console.error("目标元素未找到");
    }
  }
  // 新增方法
  static renderToContainer(PageClass, containerId) {
    const container = document.getElementById(containerId);
    container.innerHTML = "";
    container.appendChild(new PageClass().render());
  }
}
